package org.example.bobofish.user.domain.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.example.bobofish.user.application.facade.entity.LockUserRightsRequest;
import org.example.bobofish.user.domain.model.UserRightsInfoModel;
import org.example.bobofish.user.domain.repository.UserRightsRepository;
import org.example.bobofish.user.infrastructure.persistence.dao.UserRightsInfoDao;
import org.example.bobofish.user.infrastructure.persistence.entity.UserRightsInfo;
import org.example.bobofish.user.domain.service.UserRightsService;
import org.example.bobofish.common.exception.BizException;
import org.example.bobofish.common.exception.RetCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserRightsServiceImpl extends ServiceImpl<UserRightsInfoDao, UserRightsInfo> implements UserRightsService {

    @Autowired
    private UserRightsRepository userRightsRepository;

    @Override
    public List<UserRightsInfoModel> getUserRightsList(String userId) {
        return userRightsRepository.getUserRightsList(userId);
    }

    @Override
    public void operateRights(LockUserRightsRequest userRightsRequest) {
        if (userRightsRequest == null || StringUtils.isEmpty(userRightsRequest.getUserId())
                || StringUtils.isEmpty(userRightsRequest.getRightNo())) {
            throw BizException.build(RetCode.EXCEPTION, "参数异常");
        }
        userRightsRepository.operateRights(userRightsRequest);
    }
}
